const {
    association
} = require('../modules/index')

//数据库操作类
class associationDao {

    // 获取单个协会
    static async getAssociationInfo(id) {
        return await association.findOne({
            where: {
                id
            }
        })
    }

    // 获取所有协会
    static async getAllAssociation() {
        return await association.findAll({
            raw: true //返回原始数据
        })
    }


    //新增协会
    static async postAssociation(associationInfo) {
        return await association.create({
            association_title: associationInfo.association_title,
            association_time: associationInfo.association_time,
            association_status: associationInfo.association_status,
            association_content: associationInfo.association_content,
            association_sperson: associationInfo.association_sperson,
            association_phone: associationInfo.association_phone,
            association_photo: associationInfo.association_photo,
        })
    }

    //编辑协会
    static async putAssociation(associationInfo) {
        return await association.update({
            association_name: associationInfo.association_name,
            contactPerson: associationInfo.contactPerson,
            contactMobile: associationInfo.contactMobile,
            officeAddress: associationInfo.officeAddress,
            email: associationInfo.email,
            introduce: associationInfo.introduce,
            status: associationInfo.status,
            frozenRemark:associationInfo.frozenRemark,
            remark: associationInfo.remark,
            auditOptions: associationInfo.auditOptions,
            logo: associationInfo.logo
        }, {
            where: {
                id: associationInfo.id
            }
        })
    }


    // 删除协会
    static async delectAssociation(body) {
        return await association.destroy({
            where: {
                id: body
            }
        })
    }



}

module.exports = associationDao